//
//  delegateShangViewController.m
//  gpos_app
//
//  Created by apple on 2018/9/27.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "delegateShangViewController.h"
#import "Masonry.h"
#import "GPosAPI.h"
#import "SVProgressHUD.h"
#import "WKProgressHUD.h"
#import "XMRegisterViewController.h"
#import "delegListViewController.h"


@interface delegateShangViewController ()
@property (nonatomic,strong)UIView * identityView;
@property (nonatomic,strong)WKProgressHUD *hud;
@property (nonatomic,strong)NSString * number;
@property (nonatomic,strong)NSString * sume;


@end

@implementation delegateShangViewController

//改变状态栏
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    self.tabBarController.tabBar.hidden=YES;
    self.navigationController.navigationBar.topItem.title = @"我是代理商";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];;
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.tintColor=[UIColor blackColor];
    self.title = @"我是代理商";
    [self loadData];
}

- (void)loadData{
    //requestSalesCommissionWithParams
    __weak typeof(self) weakSelf = self;
    int user = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
    NSDictionary * params = @{
                              @"userId" : @(user),
                              };
//    NSLog(@"oj---%@",params);
    [GPosAPI requestSalesCommissionWithParams:params andCallback:^(id obj) {
        NSLog(@"储存列表---%@",obj);
        
        if (obj==nil) {
            weakSelf.hud=[WKProgressHUD popMessage:@"请求失败" inView:self.view duration:1 animated:YES];
            
        }else{
            
            if ([[obj objectForKey:@"code"] intValue] == 200) {
                NSDictionary * dic = [obj objectForKey:@"data"];
                weakSelf.number = [dic objectForKey:@"number"];
                NSDecimalNumber * number = [dic objectForKey:@"sum"];
                weakSelf.sume = [NSString stringWithFormat:@"%@",@(number.floatValue)];
                
            }else if ([[obj objectForKey:@"code"] intValue] == 401 || [[obj objectForKey:@"code"] intValue] == 402){
                UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                //storyboard里的ID
                XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
                vc.navigationController.navigationBarHidden=NO;
                //                    //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=vc;
                
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }else{
                
                weakSelf.hud=[WKProgressHUD popMessage:[obj objectForKey:@"message"] inView:self.view duration:1 animated:YES];
            }
            
            
        }
        
                [weakSelf UIviewLoad];
    }];
    
    
}

- (void)UIviewLoad{
    self.identityView = [[UIView alloc] init];
    self.identityView.backgroundColor = [UIColor whiteColor];
    self.identityView.layer.cornerRadius = 10;
    [self.view addSubview:self.identityView];
    [self.identityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(kNavbarHeight + 20);
        make.left.equalTo(self.view).with.offset(10);
        make.right.equalTo(self.view).with.offset(-10);
        make.height.equalTo(@160);
    }];
    
  
    
    UIImageView *identityImage = [[UIImageView alloc] init];
    [self.identityView addSubview:identityImage];
    identityImage.image = [UIImage imageNamed:@"pic3"];
    
    UIImageView *maximumImage = [[UIImageView alloc] init];
    [self.identityView addSubview:maximumImage];
    maximumImage.image = [UIImage imageNamed:@"pic4"];
    [@[ identityImage, maximumImage] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:20 leadSpacing:20 tailSpacing:20];
    
    [@[ identityImage, maximumImage] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.identityView).offset(15);
        
    }];
   
    
    UILabel * identityOne = [[UILabel alloc] init];
    identityOne.text = self.number;
    identityOne.textColor = [UIColor blueColor];
    identityOne.textAlignment = NSTextAlignmentCenter;
    identityOne.font = [UIFont systemFontOfSize:14];
    [self.identityView addSubview:identityOne];
    [identityOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(identityImage.mas_bottom).with.offset(10);
        make.centerX.equalTo(identityImage);
    }];
    UILabel * identityLabel = [[UILabel alloc] init];
    identityLabel.text = @"机器销量";
    identityLabel.textColor = [UIColor blackColor];
    identityLabel.textAlignment = NSTextAlignmentCenter;
    identityLabel.font = [UIFont systemFontOfSize:14];
    [self.identityView addSubview:identityLabel];
    [identityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(identityOne.mas_bottom).with.offset(10);
        make.centerX.equalTo(identityImage);
    }];
//
//
    
//
    UILabel * maximumOne = [[UILabel alloc] init];
    maximumOne.text = self.sume;
    maximumOne.textColor = [UIColor blueColor];
    maximumOne.textAlignment = NSTextAlignmentCenter;
    maximumOne.font = [UIFont systemFontOfSize:14];
    [self.identityView addSubview:maximumOne];
    [maximumOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(maximumImage.mas_bottom).with.offset(10);
        make.centerX.equalTo(maximumImage);
    }];
    
    UILabel * maximumLabel = [[UILabel alloc] init];
    maximumLabel.text = @"业绩提成";
    maximumLabel.textColor = [UIColor blackColor];
    maximumLabel.textAlignment = NSTextAlignmentCenter;
    maximumLabel.font = [UIFont systemFontOfSize:14];
    [self.identityView addSubview:maximumLabel];
    [maximumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(maximumOne.mas_bottom).with.offset(10);
        make.centerX.equalTo(maximumImage);
    }];
    
    
    UIButton * awardButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [awardButton addTarget:self action:@selector(awardAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.identityView addSubview:awardButton];
    [awardButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.identityView).with.offset(5);
        make.left.equalTo(self.identityView).with.offset(5);
        make.right.equalTo(self.identityView).with.offset(-5);
        make.bottom.equalTo(self.identityView).with.offset(-5);
    }];
//
}


//培训奖
- (void)awardAction:(UIButton *)sender {
    delegListViewController * VC = [[delegListViewController alloc] init];
    VC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:VC animated:YES];
    VC.hidesBottomBarWhenPushed = NO;
    
}
@end
